package com.hao.rabbitmqproduce.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class TTLConfig {
    public static final String EXCHANGE_NAME="boot_ttl_exchange";
    public static final String QUEUE_NAME="boot_ttl";

    @Bean("ttlExchange")
    public Exchange ttlExchange(){
        return ExchangeBuilder.topicExchange(EXCHANGE_NAME).build();
    }

    @Bean("ttlQueue")
    public Queue ttlQueue(){
        Map<String, Object> map = new HashMap<>();
        map.put("x-message-ttl",10000);
        return QueueBuilder.durable(QUEUE_NAME).withArguments(map).build();
    }

    @Bean
    public Binding bindingTTL(@Qualifier("ttlExchange") Exchange exchange,@Qualifier("ttlQueue") Queue queue){
        return BindingBuilder.bind(queue).to(exchange).with("ttl.#").noargs();
    }
}
